package cn.smbms.controller;

import java.util.HashMap;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.smbms.pojo.Order_detail;
import cn.smbms.pojo.User;
import cn.smbms.service.order_detail.OrderDetailService;
import cn.smbms.tools.Constants;

import com.alibaba.fastjson.JSON;
import com.sun.istack.logging.Logger;

@Controller
@RequestMapping("/OrderDetail")
public class OrderDetailController {
	private Logger logger = Logger.getLogger(OrderDetailController.class);
	@Resource
	private OrderDetailService orderDetailService;

	// 进入物流信息页面
	@RequestMapping(value = "/sys/wuli/{id}")
	public String wuli(@PathVariable String id, HttpSession session, Model model) {
		int userid = ((User) session.getAttribute(Constants.USER_SESSION))
				.getId();

		Order_detail order_dea = orderDetailService.getOrder_detailId(userid,
				Integer.parseInt(id));
		model.addAttribute("order", order_dea);
		return "wuliu";
	}

	// 进入全部订单的方法
	@RequestMapping(value = "/sys/Order.html")
	public String Order(Model model, HttpSession session) {
		int userid = ((User) session.getAttribute(Constants.USER_SESSION))
				.getId();
		List<Order_detail> list = orderDetailService.getOrder_details(userid);
		model.addAttribute("list", list);
		return "order";
	}

	// 待发货
	@RequestMapping(value = "/sys/Ordertwo.html")
	public String OrderTwo(Model model, HttpSession session) {
		int userid = ((User) session.getAttribute(Constants.USER_SESSION))
				.getId();
		List<Order_detail> list = orderDetailService.getOrder_details(userid);
		model.addAttribute("list", list);
		System.out.println(list.size());
		return "ordertwo";
	}

	// 待付款
	@RequestMapping(value = "/sys/Orderthree.html")
	public String Orderthree(Model model, HttpSession session) {
		int userid = ((User) session.getAttribute(Constants.USER_SESSION))
				.getId();
		List<Order_detail> list = orderDetailService.getOrder_details(userid);
		model.addAttribute("list", list);
		System.out.println(list.size());
		return "orderthree";
	}

	// 待收货
	@RequestMapping(value = "/sys/Orderfour.html")
	public String Orderfour(Model model, HttpSession session) {
		int userid = ((User) session.getAttribute(Constants.USER_SESSION))
				.getId();
		List<Order_detail> list = orderDetailService.getOrder_details(userid);
		model.addAttribute("list", list);
		System.out.println(list.size());
		return "orderfour";
	}

	// 取消订单
	@RequestMapping(value = "/delOrder")
	@ResponseBody
	public Object delOrder(@RequestParam Integer id) {
		System.out.println("我进来了");
		HashMap<String, String> resultMap = new HashMap<String, String>();
		if (orderDetailService.Orderdel(id)) {
			System.out.println("删除成功");
			resultMap.put("delOrder", "true");
		} else {
			System.out.println("删除失败");
			resultMap.put("delOrder", "false");
		}
		return JSON.toJSONString(resultMap);
	}
}
